Title: Redirect after logging in based on the user role

Publish Date: Wed, 30 Mar 2016 07:00:38 +0000

Categories: Uncategorized

Content:

Not every user should be able to log in to the Dashboard, and WooCommerce already prevents this. But you may want to change it for somebody or just use a different page.

By default WooCommerce redirects the user to the My Account page after a successful login.

You can redirect after logging in and use a custom URL based on the user role, like the Dashboard for admins and My Account page for customers.



Add this code at the end of the file functions.php in wp-content/themes/your-child-theme-name/:

https://gist.github.com/woogist/f49a8866e162594dd06b

Delete the sign <?php on first line if you are having errors come up after saving the file.

If you need to change the URL for a specific role you can use the function [ablank href="http://codex.wordpress.org/Function_Reference/get_permalink"]get_permalink()[/ablank] passing the page ID to return its URL:

get_permalink( 150 );


This code will return the URL to the page with ID 150.
